module.exports = {
	getSysSetting:{
		type:"",
		url:"/webservice/sysSettingItem.action"
	},
	login:{
		type:"",
		url:"/webservice/usrEmployeeItemLogin.action"
	},
    getNotices:{
        type:'',
        url:"/webservice/bizNoticeList.action"
    },
    getActivity:{
        type:'',
        url:"/webservice/bizActivityList.action"
    },
    getNoticeTypes:{
        type:'',
        url:'/webservice/bizNoticeTypeList.action'
    },
    getNotice:{
        type:'',
        url:'/webservice/bizNoticeItem.action'
    },
	getItems:function(opts,cb){
        var that = this
		return $.ajax({
            cache: false,
            type: "GET",
            url: opts.method.url,
            data:opts.query,
               success: function (res) {
                // 定义一个handleData function
                // 然后res = handleData(res)
                    res = that.handleData(res)
                    // res = {
                    //     success:res.success,
                    //     errorCode:res.errorCode,
                    //     message: res.message
                    // }

                        // avalon.router.redirect("errors")  
                    
                    
                    cb(res);
            }
        });
	},
    postItems:function(opts,cb){
        var that = this
        return $.ajax({
            cache: false,
            type: "POST",
            url: opts.method.url,
            data:opts.query,
               success: function (res) {
                    res = that.handleData(res)
                    // res = {
                    //     success:res.success,
                    //     errorCode:res.errorCode,
                    //     message: res.message
                    // }

                        // avalon.router.redirect("errors")  
                    
                  
                    cb(res);
            }
        });
    },
    getUserInfo:function(){
        return window.localStorage.getItem('avaLessonEvaluationUser')?window.localStorage.getItem('avaLessonEvaluationUser'):window.sessionStorage.getItem('avaLessonEvaluationUser')?window.sessionStorage.getItem('avaLessonEvaluationUser'):''
    },
    clearUserInfo:function(){
        if(window.localStorage.getItem('avaLessonEvaluationUser')){
            window.localStorage.removeItem('avaLessonEvaluationUser')
        }
        if(window.sessionStorage.getItem('avaLessonEvaluationUser')){
            window.sessionStorage.removeItem('avaLessonEvaluationUser')
        }
    },
    handleData:function(data){
        var that = this
        var items;
        if (data.constructor==Object){
            items = {}
        }else if(data.constructor==Array){
            items = []
        }
        for(var item in data){
            if(data[item]==null){
                items[item] = ''
            }else if(typeof data[item] === "object"){
                items[item] = that.handleData(data[item])
            }else{
                items[item] = data[item]
            }
        }
        return items
    }
}